﻿using B.S.Data.MES.API.Applications.WorkOrderManagement.Commands;
using B.S.Domain.Process.ProcessrouteName;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.WorkOrderManagement.CommandHandlers
{
    public class GetProcessrouteCommandHandler : IRequestHandler<GetProcessrouteCommand, APIRequst<List<Processroute>>>
    {
        private readonly IBaseRepository<Processroute> _processrouteRepository;
        public GetProcessrouteCommandHandler(IBaseRepository<Processroute> processrouteRepository)
        {
            _processrouteRepository = processrouteRepository;
        }
        public Task<APIRequst<List<Processroute>>> Handle(GetProcessrouteCommand request, CancellationToken cancellationToken)
        {
            var side = _processrouteRepository.GetAll();
            if(side==null)
            {
                return Task.FromResult(new APIRequst<List<Processroute>>
                {
                    Code=RequstCode.失败,
                    Msg=RequstCode.失败.ToString(),
                });

            }
            return Task.FromResult(new APIRequst<List<Processroute>>
            {
                Data=side.ToList(),
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString(),
            });
        }
    }
}
